import {Injectable} from '@angular/core';
import {Router} from '@angular/router';

@Injectable({
    providedIn: 'root'
})
export class PermissionsService {

    constructor(
        private router: Router
    ) {
    }

    // 登录
    getToken() {
        const token = String(Date.now());
        localStorage.setItem('SmartAppToken', token);
        this.router.navigateByUrl('tabs');
    }

    // 判断是否登录
    canActivate() {
        const token = localStorage.getItem('SmartAppToken');
        if (token) {
            return true;
        } else {
            this.router.navigateByUrl('/login');
            return false;
        }
    }
}
